package test3_17.Auto;

public class Auto {

    /*
    建立一个汽车Auto类，包括轮胎个数，汽车颜色，车身重量、速度等成员变量。
    并通过不同的构造方法创建实例。至少要求： 汽车能够加速，减速，停车。
     */

    private int tire;
    private String color;
    private double weight;
    private double speed;

    public Auto() {
        this(40, 2000, "黄色", 4);
    }

    public Auto(double speed, double weight, String color, int tire) {
        this.speed = speed;
        this.weight = weight;
        this.color = color;
        this.tire = tire;
    }

    public int getTire() {
        return tire;
    }

    public void setTire(int tire) {
        this.tire = tire;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public double getSpeed() {
        return speed;
    }

    public void setSpeed(double speed) {
        this.speed = speed;
    }

    public void speedUp(int n) {
        if (n > 0) {
            speed += n;
            System.out.println("当前速度为：" + speed);
        }
    }

    public void speedDown(int m) {
        if (speed > 0 && speed > m) {
            speed -= m;
        } else if (speed < m && speed > 0) {
            speed = 0;
            stop();
        }
        System.out.println("当前速度为：" + speed);
    }

    public void stop(){
        if(speed == 0){
            System.out.println("已停车");
        }
    }
}